package study.cell_game.objects;

import org.andengine.entity.sprite.Sprite;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import study.cell_game.enums.PlayerColor;
import study.cell_game.objects.tokens.Token;
import study.cell_game.utils.TapManager;

public class CellSprite extends Sprite {
	private Cell cell;

	public CellSprite(float pX, float pY, ITextureRegion pTextureRegion,
			VertexBufferObjectManager VertexBufferObjectManager, Cell cell) {
		super(pX, pY, pTextureRegion, VertexBufferObjectManager);
		this.cell = cell;
	}

	@Override
	public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
		
		//if(cell.isMapCell()){
			if (TouchEvent.ACTION_DOWN == (pSceneTouchEvent.getAction())) {
				if(cell.getToken() != null){
					cell.getToken().getPlayerColor().onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
				} else {
					TapManager.getInstance().tapCell(this);
				}
			}
		//}
		return true;
	}

	public Cell getCell() {
		return this.cell;
	}
}
